<?php
class BackupController extends Controller{
  public $isActivated = 0;
          public function accessRules()
		 {
			return array(
			   array(
					'allow',  // allow all users to access 'index' and 'view' actions.
					'expression'=>'$user->rights == 3',
				),
				array(
					'deny',  // deny all users
					'users'=>array('*'),
					'message'=>'You do not have access to this page ! ! ',
				),
				
			);
		 
		}
    public function actionIndex(){
		$this->breadcrumbs=array(
               '备份和导入'=>array('index'),
               '备份和导入',
             );
		$this->render("index");
		
	}
	public function actionExport(){
		
		$D = new DLDatabaseHelper;
		$D->export(true,true,date('Y-m-d_H:i:s').'backup.sql.gz',false);
		
	}
	public function actionImport(){
		$D = new DLDatabaseHelper;
		//var_dump($_FILES);die();
		$request = Yii::app()->request;
		if($request->requestType == 'POST'){
			
			if($_FILES['sqlfile']['name'] == ''){
				
				Yii::app()->user->setFlash('backup','空文件！！');
			    $this->redirect(array('backup/index'));
				
			}else{
				$sql_file_path = './images/importsqlfile/'.$_FILES['sqlfile']['name'];
				if(move_uploaded_file($_FILES["sqlfile"]["tmp_name"],$sql_file_path)){
				
					if($D->import($sql_file_path)){
							
							Yii::app()->user->setFlash('backup','导入成功');
							
							$this->redirect(array('backup/index'));
					}else{
						
						
						Yii::app()->user->setFlash('backup','导入失败！！');
						$this->redirect(array('backup/index'));
						
					}
					
				}else{
					Yii::app()->user->setFlash('backup','文件上传失败!!');
			    $this->redirect(array('backup/index'));
					
				}		
				
				
				
			}			
		}else{
			Yii::app()->user->setFlash('backup','错误的访问');
			$this->redirect(array('backup/index'));
		}
		
		
	}
}
?>